package com.robot.agent.controller;

import com.alibaba.fastjson.JSON;
import com.robot.agent.pojo.Agent;
import com.robot.agent.pojo.AgentMember;
import com.robot.agent.service.AgentMemberService;
import com.robot.agent.service.AgentService;
import entity.PageResult;
import entity.Result;
import entity.StatusCode;
import io.jsonwebtoken.Claims;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * 代理商名下会员
 *
 * @author lin
 */
@RestController
@CrossOrigin
@RequestMapping("/agentMember")
public class AgentMemberJsonController {
    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private AgentMemberService agentMemberService;

    /**
     * 增加AgentMember
     *
     * @param agentMember
     */
    @RequestMapping(value = "third/addAgentMemberByAgentMember", method = RequestMethod.POST, produces = "application/json; charset=utf-8")
    public void thirdAddAgentMemberByAgentMember(@RequestBody String agentMember) {
        agentMemberService.add(JSON.parseObject(agentMember, AgentMember.class));
    }

    /**
     * 修改AgentMember
     *
     * @param agentMember
     */
    @RequestMapping(value = "third/updateAgentMemberByAgentMember", method = RequestMethod.PUT, produces = "application/json; charset=utf-8")
    public void thirdUpdateAgentMemberByAgentMember(@RequestBody String agentMember) {
        agentMemberService.update(JSON.parseObject(agentMember, AgentMember.class));
    }

    /**
     * 删除AgentMember
     *
     * @param id
     */
    @RequestMapping(value = "third/deleteAgentMemberById/{id}", method = RequestMethod.DELETE, produces = "application/json; charset=utf-8")
    public void thirdDeleteAgentMemberById(@PathVariable String id) {
        agentMemberService.deleteById(id);
    }

    /**
     * 通过agentId和memberId查找代理商名下的某一会员
     *
     * @param agentId
     * @param memberId
     * @return
     */
    @RequestMapping(value = "third/findAgentMemberByAgentIdAndMemberId/{agentId}/{memberId}", method = RequestMethod.GET, produces = "application/json; charset=utf-8")
    public String thirdFindAgentMemberByAgentIdAndMemberId(@PathVariable String agentId, @PathVariable String memberId) {
        return JSON.toJSONString(agentMemberService.findByAgentIdAndMemberId(agentId, memberId));
    }
}
